package com.xiechanglei.html;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;

import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.filters.HasAttributeFilter;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;

public class HtmlParserDemmo {
	public static void main(String[] args) throws IOException, ParserException {
		URL u = new URL("http://www.360doc.com/content/12/0806/10/7471983_228598216.shtml");
		URLConnection connection = u.openConnection();
		Parser parser = new Parser(connection);
		NodeFilter filter = new AndFilter(new TagNameFilter("div"), new HasAttributeFilter("id", "flowimg5"));
		NodeList nodes = parser.parse(filter);
		String html = nodes.toHtml();
		System.out.println(html);
	}
}
